package cn.java81.jdbc;

import cn.java81.util.DbUtil;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class AddSubject2 {
    //增加新课程
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);//输入新课的信息
        System.out.print("请输入课程名：");
        String sname=sc.next();
        System.out.print("请输入课时：");
        int classhour=sc.nextInt();
        System.out.println("请输入年级编号：");
        long gradeid=sc.nextLong();
        Connection con= DbUtil.getConnection();
        Statement st=null;
        try {
            st=con.createStatement();
            String sql="insert into s_subject(subjectname,classhour,gradeid)" +
                    "values('"+sname+"',"+classhour+","+gradeid+")";
            System.out.println(sql);
            int r=st.executeUpdate(sql);
            System.out.println("新增了"+r+"门课！");
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DbUtil.close(null,st,con);
        }
    }
}
